#ifndef AVIATION_FLIGHT_H
#define AVIATION_FLIGHT_H

#include "flightnumber.h"
#include "date.h"
#include "time_24.h"
#include "airport.h"
#include "util.h"

#include <string>

#include <boost/serialization/nvp.hpp>

namespace aviation
{

/// Represents a Flight database entry.
class Flight
{
public:

	typedef std::string String;

	// Default constructor, creates a Flight with reasonable default data.
	Flight();
	// Copy from another flight
	Flight(const Flight& other);
	// Create from FCGDATA line (must be robust)
	Flight(const String& fcgString);
	//Create a FCGDATA line from strings
	Flight(const FlightNumber& flightNumber, const Date& date, const Time& time, const Airport& source, const Airport& destination, const unsigned int standardSeats, const unsigned int firstSeats);
	~Flight();

	/// Serialization (file I-O) function.
	/// \param ar A boost::archive formatter type.
	/// \param version The file version.
	template <class Archive>
	void serialize(Archive& ar, const unsigned int version);

	/// Assignment operator
	Flight& operator=(const Flight& other);

	/// Equality operator, determines if *this == other.
	/// \returns True if they are the same or false if they are different.
	const bool operator==(const Flight& other) const;
	/// Inequality operator.
	/// \returns True if they are different or false if they are the same.
	const bool operator!=(const Flight& other) const;

	/// Strict weak ordering operator.
	/// \returns true if the first Flight is strictly less than the second.
	const bool operator<(const Flight& other) const;

	/// Returns a copy of the FlightNumber.
	const FlightNumber GetFlightNumber() const;
	/// Returns a copy of the Date.
	const Date GetDate() const;
	/// Returns a copy of the Time.
	const Time GetTime() const;
	/// Returns a copy of the source airport.
	const Airport GetSource() const;
	/// Returns a copy of the destination airport.
	const Airport GetDestination() const;
	/// Returns the maximum number of standard class seats.
	const unsigned GetMaxStandardSeats() const;
	/// Returns the maximum number of first class seats.
	const unsigned GetMaxFirstSeats() const;
	/// Returns the unique ID integer.
	const unsigned GetID() const;
	
	/// Formats the Flight as a string.
	const String AsString() const;

private:

	FlightNumber m_flightNumber;
	Date m_date;
	Time m_time;

	Airport m_source;
	Airport m_dest;

	unsigned m_maxStandardSeats;
	unsigned m_maxFirstSeats;
	unsigned m_ID;
};

template <class Archive>
void Flight::serialize(Archive& ar, const unsigned int version)
{
	ar & BOOST_SERIALIZATION_NVP(m_flightNumber);
	ar & BOOST_SERIALIZATION_NVP(m_time);
	ar & BOOST_SERIALIZATION_NVP(m_date);
		
	ar & BOOST_SERIALIZATION_NVP(m_source);
	ar & BOOST_SERIALIZATION_NVP(m_dest);

	ar & BOOST_SERIALIZATION_NVP(m_maxStandardSeats);
	ar & BOOST_SERIALIZATION_NVP(m_maxFirstSeats);

	ar & BOOST_SERIALIZATION_NVP(m_ID);
}

} // namespace aviation

#endif // AVIATION_FLIGHT_H